<!DOCTYPE html>
<html lang="en">
<title>链接转换</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">链接生成</h5>
                </div>
                <div class="ibox-content">
                
                    <form method="post" class="form-horizontal" action="activity_save" id="from" accept-charset="UTF-8">
                       
                        <div class="form-group"><label class="col-sm-2 control-label">原始链接</label>
                            <div class="col-sm-10">
                                <input type="text" id="url"  name="url" class="form-control" placeholder="必填，原始链接">
                                <p>必须是完整链接，比如：http://apt.heatup.cn/home/course_details?orderType=1&courseId=1126&isVipUsed=0&userLevel=1</p>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">活动类型</label>
                            <button type="button" class="btn btn-primary" style='float:left' id="btn_submit">确认生成</button>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                        	<input type="hidden" id="couponId" name ="couponId">
                            <label class="col-sm-2 control-label">生成后的链接</label>
                            <div  class="col-sm-10" id="">
                            <textarea id='CouponIdChild' rows="5" readonly="readonly" cols="100"></textarea>
                            </div>
                        </div>
                        <div class="form-group"><label class="col-sm-2 control-label"></label>
                            <button type="button" class="btn btn-primary" style='float:left' id="copy">复制链接</button>
                        </div>
                       
            </div>
        </div>
    </div>
</div>
<link href="${baseUrl}css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
<script type="text/javascript" src="${baseUrl}js/main.js"></script>
<script src="${baseUrl}js/plugins/clockpicker/clockpicker.js"></script>
<script src="http://www.daimajiayuan.com/member/templets/js/jquery.zclip.min.js"></script> 
<script>
    $(document).ready(function () {
    	var testHost = 'http://test.heatup.cn';
    	var proHost = 'http://h5.heatup.cn';
    	
   	
   	 //$("#copy").click(function(){
   	//	var testCode = $("#CouponIdChild").text();
   	 //   if (copy2Clipboard(testCode) != false) {
   	  //      alert("已经复制到粘贴板，你可以使用Ctrl+V 贴到需要的地方去了哦！  ");
   	 //   }
   	// })
   	 $('#copy').zclip({ 
            path: "${baseUrl}js/ZeroClipboard.swf", 
            copy: function(){ 
            	var aa = $("#CouponIdChild").val();
                return aa; 
  　　　 　　	},
        	afterCopy: function() { //复制后操作方法 
        		swal({
                    title: "提示",
                    html: '已复制，尽情粘贴吧',
                    type: "success"
                });
            } 
    }); 
    $("#btn_submit").click(function(){
    	var url = $("#url").val();
    	var msg = '';
    	if(url.length == 0){
    		msg = msg + '原始链接不能为空'+'</br>';
    	}
    	if(msg.length > 0){
    		swal({
                title: "生成错误",
                html: msg,
                type: "error"
            });
    		return false;
    	}
    	
    	if(url.indexOf('http://diet-gym.heatup.cn') < 0 || url.indexOf('http://apt.heatup.cn') < 0) {
    		if(msg.length > 0){
        		swal({
                    title: "生成错误",
                    html: '原始链接必须是完整的URL',
                    type: "error"
                });
        		return false;
        	}
    	}
    	
    	debugger;
    	if(url.indexOf('http://diet-gym.heatup.cn') >=0 ) {
    		var paraseUrl = encodeURIComponent($("#url").val().replace('http://diet-gym.heatup.cn',''));
    		var tempUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf179373cfe912568&redirect_uri=http%3A%2F%2Fdiet-gym.heatup.cn%2Fapi%2Fredirect%2FweiXinJump%3Fpath%3D"+paraseUrl+"&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect";
    		console.log(tempUrl)
    		 $("#CouponIdChild").val(tempUrl);
    	} else if(url.indexOf('http://apt.heatup.cn') >=0) {
    		var paraseUrl = encodeURIComponent($("#url").val().replace('http://h5.heatup.cn',''));    	
    		console.log(paraseUrl)
    		var tempUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9876e83544bf2e49&redirect_uri=http%3A%2F%2Fapt.heatup.cn%2Fapi%2Fredirect%2FweiXinJump%3Fpath%3D"+paraseUrl+"&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect";
    		console.log(tempUrl)
    		$("#CouponIdChild").val(tempUrl);
    	}
    	
     });
   	function copy2Clipboard(txt) 
    {
	    
    	if (window.clipboardData) {
   	        window.clipboardData.clearData();
   	        window.clipboardData.setData("Text", txt);
   	    }
   	    else if (navigator.userAgent.indexOf("Opera") != -1) {
   	        window.location = txt;
   	    }
   	    else if (window.netscape) {
   	        try {
   	            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   	        }
   	        catch (e) {
   	            alert("您的firefox安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重试，相对路径为firefox根目录/greprefs/all.js");
   	            return false;
   	        }
   	        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   	        if (!clip) return;
   	        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   	        if (!trans) return;
   	        trans.addDataFlavor('text/unicode');
   	        var str = new Object();
   	        var len = new Object();
   	        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   	        var copytext = txt; str.data = copytext;
   	        trans.setTransferData("text/unicode", str, copytext.length * 2);
   	        var clipid = Components.interfaces.nsIClipboard;
   	        if (!clip) return false;
   	        clip.setData(trans, null, clipid.kGlobalClipboard);
   	    }
    	
    }
});
</script>
</@body.page>
</html>